﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace _3.WordExtraction
{
    class Program
    {
        static void Main(string[] args)
        {
            string text = "Testing is important. We need to test everything";
            string word = "test";

            ExtractWordsFromText(word, text);
        }

        public static void ExtractWordsFromText(string word, string text)
        {
            string pattern = @"\b[\w]*" + word + @"[\w]*\b";
            Regex regex = new Regex(pattern,RegexOptions.IgnoreCase);
            MatchCollection matches = regex.Matches(text);

            for (int i = 0; i < matches.Count; i++)
			{
			    Console.WriteLine( matches[i].Value + " at " + matches[i].Index);
			}
        }
    }
}
